<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>购物车</title>
<link rel="stylesheet" type="text/css" href="css/style5.css">
		<link rel="stylesheet" type="text/css" href="css/css.css" />
		<style type="text/css">
			#ip input{
				width: 300px;
				height: 20px;
			}
			input:focus{
			    outline: 0;
			    border: 1px solid #f95d5d;
			    box-shadow: 0px 0px 10px 0px #f95d5d;
	  		}
	  		#ip{
	  			font-size: 20px;
	  		}
		</style>
		<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
		<script type="text/javascript">
			$(function() {
				var region = $("#region");
				var address = $("#address");
				var number_this = $("#number_this");
				var name = $("#name_");
				var phone = $("#phone");
				$("#sub_setID").click(function() {
					var input_out = $(".input_style");
					for (var i = 0; i <= input_out.length; i++) {
						if ($(input_out[i]).val() == "") {
							$(input_out[i]).css("border", "1px solid red");
							
							return false;
						} else {
							$(input_out[i]).css("border", "1px solid #cccccc");
						}
					}
				});
				var span_momey = $(".span_momey");
				var span_quantity = $(".span_quantity");
				var b = 0;
				for (var i = 0; i < span_momey.length; i++) {
					b += parseFloat($(span_momey[i]).html()*$(span_quantity[i]).html());
				}
				var out_momey = $(".out_momey");
				out_momey.html(b);
				$(".shade_content").hide();
				$(".shade").hide();
				$('.nav_mini ul li').hover(function() {
					$(this).find('.two_nav').show(100);
				}, function() {
					$(this).find('.two_nav').hide(100);
				})
				$('.left_nav').hover(function() {
					$(this).find('.nav_mini').show(100);
				}, function() {
					$(this).find('.nav_mini').hide(100);
				})
				$('#jia').click(function() {
					$('input[name=num]').val(parseInt($('input[name=num]').val()) + 1);
				})
				$('#jian').click(function() {
					$('input[name=num]').val(parseInt($('input[name=num]').val()) - 1);
				})
				$('.Caddress .add_mi').click(function() {
					$(this).css('background', 'url("images/mail_1.jpg") no-repeat').siblings('.add_mi').css('background', 'url("images/mail.jpg") no-repeat')
				})
			})
			var x = Array();

			function func(a, b) {
				x[b] = a.html();
				alert(x)
				a.css('border', '2px solid #f00').siblings('.min_mx').css('border', '2px solid #ccc');
			}

			function onclick_close() {
				var shade_content = $(".shade_content");
				var shade = $(".shade");
				if (confirm("确认关闭么！此操作不可恢复")) {
					shade_content.hide();
					shade.hide();
				}
			}

			function onclick_open(buyer_name) {
				$(".shade_content").show();
				$(".shade").show();
				var input_out = $(".input_style");
				for (var i = 0; i <= input_out.length; i++) {
					if ($(input_out[i]).val() != "") {
						$(input_out[i]).val("");
					}
				}
				$.ajax({		        	
			           url: "selectBybuyer_name",//要请求的服务器url
			            data: {
			        	   buyer_name:buyer_name,
			           }, 
			           async: true,   //是否为异步请求
			           cache: false,  //是否缓存结果
			           type: "POST", //请求方式为POST
			           dataType: "json",   //服务器返回的数据是什么类型 
			           success: function(result){
			        	   $("#Buyer_address").val(result.buyer_address);
			            	$("#Buyer_name").val(result.buyer_name);
			            	$("#Buyer_phone").val(result.buyer_phone);
			           }
			         });
				 }
			
			function onclick_remove(r) {
				if (confirm("确认删除么！此操作不可恢复")) {
					var out_momey = $(".out_momey");
					var input_val = $(r).parent().prev().children().eq(1).val();
					var span_html = $(r).parent().prev().prev().children().html();
					var out_add = parseFloat(input_val).toFixed(2) * parseFloat(span_html).toFixed(2);
					var reduce = parseFloat(out_momey.html()).toFixed(2)- parseFloat(out_add).toFixed(2);
					console.log(parseFloat(reduce).toFixed(2));
					out_momey.text(parseFloat(reduce).toFixed(2))
					$(r).parent().parent().remove();
				}
			}

			

			function onclick_reduce(b) {
				var out_momey = $(".out_momey");
				var input_ = $(b).next();
				var input_val = $(b).next().val();
				if (input_val <= 1) {
					alert("商品个数不能小于1！")
				} else {
					var input_add = parseInt(input_val) - 1;
					input_.val(input_add);
					var btn_momey = parseFloat($(b).parent().prev().children().html());
					var out_momey_float = parseFloat(out_momey.html()) - btn_momey;
					out_momey.text(out_momey_float.toFixed(2));
				}
			}
		</script>
	
	</head>

	<body>
		<div  class="shopping_content">
			<span id="ip">收货人：<input type="text" id="buyer_name" name="buyer_name" placeholder="收货人"></span>
			<span id="ip">地   址：<input type="text" id="buyer_address" name="buyer_address" placeholder="送餐地址"></span>
			<span id="ip">电话：<input type="text" id="buyer_phone" name="buyer_phone" placeholder="联系电话"></span>
		</div>
		<!--
        	描述：商品内容
        -->
		<div class="shopping_content">
			<div class="shopping_table">
				<table border="1" bordercolor="#cccccc" cellspacing="0" cellpadding="0" style="width: 100%; text-align: center;">
					<tr>
						<th>商品图片</th>
						<th>商品名称</th>
						<th>商品属性</th>
						<th>商品价格</th>
						<th>商品数量</th>
						<th>商品操作</th>
					</tr>
					<c:forEach items="${sessionScope.cart.map}" var="cm">
					<tr>
						<td>
						
							<img src="uploads/${cm.value.product.product_icon}" width="55" height="55">
							
						</td>
						<td><span>${cm.value.product.product_name }<!-- 小消息下 --></span></td>
						<td>
							<span>${cm.value.product.product_description }</span>
						</td>
						<td>
							<span class="span_momey">${cm.value.product.product_price}</span>
						</td>
						<td>
							<span class="span_quantity">${cm.value.quantity}</span>
						</td>
						<td>
						    <form action="deleteCart" method="post"> 
						    <input type="hidden" name="product_id" value="${cm.value.product.product_id}">
							<input type="submit" value="删除" >	
							</form>
						</td>
					</tr>
					</c:forEach>
				</table>
				<div class="" style="width: 100%; text-align: right; margin-top: 10px;">
					<div class="div_outMumey" style="float: left;">
						总价：<span class="out_momey" id="total"></span>
						
					</div>
					<form action="toCart" method="post">
						<div>   
							<div class="right">  
								<input class="div_outMumey" style="float: right;" type="button" onclick="addOrder(${user.user_id})" value="结算"/>  
							</div>   
						</div>
					</form>
				</div>
			</div>
		</div>

		<!--
        	描述：shade 遮罩层
        -->
		<div class="shade">
		</div>
		<!--
        	描述：shade_content
        -->
		<div class="shade_content">
			<div class="col-xs-12 shade_colse">
				<button onclick="javascript:onclick_close();">x</button>
			</div>
			<div class="nav shade_content_div">
				<div class="col-xs-12 shade_title">
					修改收货地址
				</div>
				<div class="col-xs-12 shade_from">
					<form action="updateAddress" method="post">
						<div class="col-xs-12">
							<span class="span_style" id="">收货地址</span>
							<input class="input_style" type="text" name="buyer_address" id="Buyer_address" value="${lom.buyer_address }" placeholder="&nbsp;&nbsp;请输入您的详细地址" />
						</div>
						<div class="col-xs-12">
							<span class="span_style" class="span_sty" id="">姓&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;名</span>
							<input class="input_style" type="text" name="buyer_name" id="Buyer_name" value="${lom.buyer_name }" placeholder="&nbsp;&nbsp;请输入您的姓名" />
						</div>
						<div class="col-xs-12">
							<span class="span_style" id="">手机号码</span>
							<input class="input_style" type="text" name="buyer_phone" id="Buyer_phone" value="${lom.buyer_phone }" placeholder="&nbsp;&nbsp;请输入您的手机号码" />
						</div>
						<div class="col-xs-12">
							<input class="btn_remove" type="button" id="" onclick="javascript:onclick_close();" value="取消" />
							<input type="submit" class="sub_set" id="sub_setID" value="提交"  onclick="update()"/>
						</div>
					</form>
				</div>
			</div>
		</div>
	<script type="text/javascript">
		function addOrder(user_id){
			var bn = document.getElementById("buyer_name").value;
			var bp = document.getElementById("buyer_phone").value;
			var ba = document.getElementById("buyer_address").value;
			var oa = document.getElementById("total").innerHTML;
			$.ajax({        	
	            url: "addOrderMaster",//要请求的服务器url
	            data: {
	            	buyer_name: bn,
	            	buyer_phone: bp,
	            	buyer_address: ba,
	            	order_amount: oa,
	            	user_id:  user_id,
	            },
	            async: true,   //是否为异步请求
	            cache: false,  //是否缓存结果
	            type: "POST", //请求方式为POST
	            dataType: "text",   //服务器返回的数据是什么类型 
	            success: function(result){
	            	
	            	if(result == "success"){
	            		window.location.href = "jiesuan"
	            	}
					
				},
			});
		}
	</script>
	</body>
</html>